package com.healthy.support.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.support.domain.Files;
import com.healthy.support.service.IFilesService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 帮助文档Controller
 * 
 * @author ruoyi
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/Files")
public class FilesController extends BaseController
{
    @Autowired
    private IFilesService filesService;

    /**
     * 查询帮助文档列表
     */
    @RequiresPermissions("support:Files:list")
    @GetMapping("/list")
    public TableDataInfo list(Files files)
    {
        startPage();
        List<Files> list = filesService.selectFilesList(files);
        return getDataTable(list);
    }

    /**
     * 导出帮助文档列表
     */
    @RequiresPermissions("support:Files:export")
    @Log(title = "帮助文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Files files)
    {
        List<Files> list = filesService.selectFilesList(files);
        ExcelUtil<Files> util = new ExcelUtil<Files>(Files.class);
        util.exportExcel(response, list, "帮助文档数据");
    }

    /**
     * 获取帮助文档详细信息
     */
    @RequiresPermissions("support:Files:query")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(filesService.selectFilesByFileId(fileId));
    }

    /**
     * 新增帮助文档
     */
    @RequiresPermissions("support:Files:add")
    @Log(title = "帮助文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Files files)
    {
        return toAjax(filesService.insertFiles(files));
    }

    /**
     * 修改帮助文档
     */
    @RequiresPermissions("support:Files:edit")
    @Log(title = "帮助文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Files files)
    {
        return toAjax(filesService.updateFiles(files));
    }

    /**
     * 删除帮助文档
     */
    @RequiresPermissions("support:Files:remove")
    @Log(title = "帮助文档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(filesService.deleteFilesByFileIds(fileIds));
    }
}
